// pages/detailed/detailed.js
var app = getApp();
var util = require('../../utils/util');
Page({

    /**
     * 页面的初始数据
     */
    data: {
		currentPage:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
		var that = this;
		app.checkLogin(function () {
			that.getTixianlist();
			that.getStoreInfo();
			that.getSystemInfo();
		})
    },
	//获取站点配置信息 
	getSystemInfo: function () {
		var that = this;
		util.showLoading();
		util.fetchPost("/api/v1/common/system", {}, function (res) {
			if (res.state == 1) {
				that.setData({
					system: res.datas
				})
				util.hideLoading();
			} else {
				util.message(res.datas)
			}
		})
	},
	getStoreInfo: function () {
		var that = this;
		util.showLoading();
		var apiUrl = '/api/dis/member/index';
		var apiData = {
		}
		util.fetchPost(apiUrl, apiData, function (res) {
			util.hideLoading();
			if (res.state == 1) {

				that.setData({
					store_info: res.datas
				});
			} else {
				util.message(res.datas);
			}
		});
	},
	getTixianlist: function () {
		var that = this;
		var apiUrl = '/api/dis/member/withdrawal_log';
		var apiData = {
			page: that.data.currentPage,
		}
		util.fetchPost(apiUrl, apiData, function (res) {
			if (res.state == 1) {
				var tixian_list = that.data.tixian_list || [];
				for (var i in res.datas) {
					tixian_list.push(res.datas[i])
				}
				if (res.datas.length < 10) {
					that.setData({
						tishi_title: '已加载全部',
					});
				} else {
					that.setData({
						tishi_title: '正在加载中...',
					});
				}
				that.setData({
					tixian_list: tixian_list,
					ready: res.datas.length == 0 ? 1 : 2,
				})
			} else {
				util.message(res.datas)
			}
		});
	},
	makeWith: function () {
		var that = this;
		if (that.data.store_info.available_predeposit > that.data.system.dis_mini_cash_with) {
			util.confirm('您确定提现吗？', function (res) {
				util.showLoading();
				var apiUrl = '/api/dis/member/dis_withdrawal';
				var apiData = {
				}
				util.fetchPost(apiUrl, apiData, function (res) {
					if (res.state == 1) {
						util.showSuccess(res.datas);
						setTimeout(function () {
							that.getTixianlist();
							that.getUserInfo();
							that.getSystemInfo();
						}, 2000);
						util.hideLoading();
					} else {
						util.hideLoading();
						util.message(res.datas)
					}
				});
			})
		} else {
			util.showSuccess('满' + that.data.system.dis_mini_cash_with + '元才可以提现', 'none');
		}
	},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})